<template>
  <el-dialog
      :close-on-click-modal="false"
      :draggable="draggable"
      :max-width="MaxWidth"
      :model-value="show"
      :show-close="showClose"
      :top="top + 'px'"
      :width="width"
      class="cust-dialog"
      @close="close"
      align-center
  >
    <template #header="{ close, titleId, titleClass }">
      <div v-if="title" class="title">{{ title }}</div>
      <div v-else name="header"></div>
    </template>
    <div :style="{'max-height': maxLength + 'px', padding: padding}" class="dialog-body">
      <slot></slot>
    </div>
    <template v-if="buttons && buttons.length > 0 || showCancel">
      <div class="dialog-footer">
        <el-button v-if="showCancel" link @click="close">取消</el-button>
        <el-button
            v-for="btn in buttons"
            :key="btn.text"
            :type="btn.type"
            @click="btn.click"
        >
          {{ btn.text }}
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup>
const props = defineProps({
  show: {
    type: Boolean,
    default: false,
  },
  MaxWidth: {
    type: String,
    default: "780",
  },
  title: {
    type: String,
  },
  draggable: {
    type: Boolean,
    default: true,
  },
  width: {
    type: String,
    default: '30%',
  },
  top: {
    type: String,
    default: "50",
  },
  showClose: {
    type: Boolean,
    default: true,
  },
  padding: {
    type: String,
    default: "15",
  },
  maxLength: {
    type: String,
    default: "500",
  },
  buttons: {
    type: Array,
  },
  showCancel: {
    type: Boolean,
    default: true,
  },
});
const maxLength = window.innerHeight - props.top - 120;
const emit = defineEmits();

const close = () => {
  emit('close');
};
</script>
<style lang="scss">
  .cust-dialog {
  padding: 0;
  margin-bottom: 5px;
  .el-dialog__header {
    padding: 16px;
  }
  .title {
    min-height: 80px;
    overflow: auto;
    overflow-x: hidden;
    padding: 20px;
  }
  .dialog-footer {
    border-top: 1px solid #ddd;
    text-align: right;
    padding: 5px 20px;
  }
}
</style>